package com.game.framwork.gamesupport;

import android.graphics.Point;

public class AngleCal {
	public static int getAlphaByTwoPoint(Point pointO, Point pointB) {
		int alpha = 0;
		float rangeFromAToB = getRange(pointO, pointB);
		int height = pointB.y - pointO.y;
		int width = pointB.x - pointO.x;
		float asin = (float) Math.asin((float) Math.abs(height) / rangeFromAToB);
		if (height >= 0) {
			if (width >= 0) {
				alpha = 360 - (int) (asin / (Math.PI / 180));
			} else {
				alpha = 180 + (int) (asin / (Math.PI / 180));
			}
		} else {
			if (width >= 0) {
				alpha = (int) (asin / (Math.PI / 180));
			} else {
				alpha = 180 - (int) (asin / (Math.PI / 180));
			}
		}
		return alpha;
	}

	public static float getRange(Point pointA, Point pointB) {
		float x1 = pointA.x;
		float x2 = pointB.x;
		float y1 = pointA.y;
		float y2 = pointB.y;
		return (float) Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
	}
}
